<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome/css/font-awesome.min.css"/>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.0.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/502216.jpg">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/502216.jpg">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">

<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Open Sans:300,300italic,400,400italic,700,700italic|Roboto Slab:300,300italic,400,400italic,700,700italic|32px:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">
<link rel="stylesheet" href="cdn.jsdelivr.net/npm/font-awesome@4/css/font-awesome.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css">


<script id="hexo-configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    hostname: new URL('https://smilecoding.cn').hostname,
    root: '/',
    scheme: 'Gemini',
    version: '7.7.0',
    exturl: false,
    sidebar: {"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},
    copycode: {"enable":true,"show_result":true,"style":null},
    back2top: {"enable":true,"sidebar":false,"scrollpercent":true},
    bookmark: {"enable":false,"color":"#222","save":"auto"},
    fancybox: true,
    mediumzoom: false,
    lazyload: false,
    pangu: false,
    comments: {"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},
    algolia: {
      appID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    },
    localsearch: {"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},
    path: 'search.xml',
    motion: {"enable":false,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}
  };
</script>

  <meta name="description" content="TCP&#x2F;IP学习">
<meta name="keywords" content="计算机网络">
<meta property="og:type" content="article">
<meta property="og:title" content="TCP&#x2F;IP1">
<meta property="og:url" content="https:&#x2F;&#x2F;smilecoding.cn&#x2F;2021&#x2F;01&#x2F;08&#x2F;TCP-IP1&#x2F;index.html">
<meta property="og:site_name" content="林木森">
<meta property="og:description" content="TCP&#x2F;IP学习">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="https:&#x2F;&#x2F;smilecoding.cn&#x2F;2021&#x2F;01&#x2F;08&#x2F;TCP-IP1&#x2F;报文格式.jpg">
<meta property="og:updated_time" content="2021-05-20T07:17:13.197Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https:&#x2F;&#x2F;smilecoding.cn&#x2F;2021&#x2F;01&#x2F;08&#x2F;TCP-IP1&#x2F;报文格式.jpg">

<link rel="canonical" href="https://smilecoding.cn/2021/01/08/TCP-IP1/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: false,
    isPost: true
  };
</script>

  <title>TCP/IP1 | 林木森</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="林木森" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <script src="/live2d-widget/autoload.js"></script>
  <div class="container">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-meta">

    <div>
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">林木森</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
        <p class="site-subtitle">淡然处之，莫要强求</p>
  </div>

  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-fw fa-user"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
        <li class="menu-item menu-item-live">

    <a href="/live" rel="section"><i class="fa fa-fw fa-heartbeat"></i>live</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>

</nav>
  <div class="site-search">
    <div class="popup search-popup">
    <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocorrect="off" autocapitalize="none"
           placeholder="搜索..." spellcheck="false"
           type="text" id="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result"></div>

</div>
<div class="search-pop-overlay"></div>

  </div>
</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

  <a href="https://github.com/Glad-hack/Glad-hack.github.io" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content">
            

  <div class="posts-expand">
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block " lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://smilecoding.cn/2021/01/08/TCP-IP1/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/vscode.jpg">
      <meta itemprop="name" content="林木森">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="林木森">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          TCP/IP1
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-01-08 11:24:34" itemprop="dateCreated datePublished" datetime="2021-01-08T11:24:34+08:00">2021-01-08</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2021-05-20 15:17:13" itemprop="dateModified" datetime="2021-05-20T15:17:13+08:00">2021-05-20</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/TCP-IP/" itemprop="url" rel="index">
                    <span itemprop="name">TCP-IP</span>
                  </a>
                </span>
            </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2021/01/08/TCP-IP1/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2021/01/08/TCP-IP1/" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="fa fa-file-word-o"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>2.4k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="fa fa-clock-o"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>2 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h2 id="TCP-IP学习"><a href="#TCP-IP学习" class="headerlink" title="TCP/IP学习"></a>TCP/IP学习</h2><a id="more"></a>
<h3 id="OSi参考模型各个分层的作用"><a href="#OSi参考模型各个分层的作用" class="headerlink" title="OSi参考模型各个分层的作用"></a>OSi参考模型各个分层的作用</h3><div class="table-container">
<table>
<thead>
<tr>
<th></th>
<th>分层名称</th>
<th style="text-align:center">功能</th>
<th style="text-align:left">功能概览</th>
</tr>
</thead>
<tbody>
<tr>
<td>7</td>
<td>应用层</td>
<td style="text-align:center">针对特定应用的协议</td>
<td style="text-align:left">电子邮件：电子邮件协议；远程登录：远程登陆协议；文件传输：文件传输协议</td>
</tr>
<tr>
<td>6</td>
<td>表示层</td>
<td style="text-align:center">设备固有数据与网络标准数据格式的转换</td>
<td style="text-align:left">接受不同表示形式的信息，如文字流，图像，声音等。</td>
</tr>
<tr>
<td>5</td>
<td>会话层</td>
<td style="text-align:center">通信管理，负责建立于断开连接，管理传输层以下的分层</td>
<td style="text-align:left">何时建立连接，何时断开连接，以及保持多久的连接</td>
</tr>
<tr>
<td>4</td>
<td>传输层</td>
<td style="text-align:center">管理两个节点之间的数据通信，保证数据可靠传输</td>
<td style="text-align:left">是否有数据丢失</td>
</tr>
<tr>
<td>3</td>
<td>网络层</td>
<td style="text-align:center">地址管理与路由选择</td>
<td style="text-align:left">经过那个路由传递到目标地址</td>
</tr>
<tr>
<td>2</td>
<td>数据链路层</td>
<td style="text-align:center">互联设备间传送和识别数据帧</td>
<td style="text-align:left">数据帧与比特流之间的转换</td>
</tr>
<tr>
<td>1</td>
<td>物理层</td>
<td style="text-align:center">以0/1代表电压的高低，灯光的闪灭</td>
<td style="text-align:left">比特流与电子信号之间的转换</td>
</tr>
</tbody>
</table>
</div>
<h3 id="TCP-IP分层模型"><a href="#TCP-IP分层模型" class="headerlink" title="TCP/IP分层模型"></a>TCP/IP分层模型</h3><div class="table-container">
<table>
<thead>
<tr>
<th>分层名称</th>
<th>协议</th>
<th>OSI参考模型</th>
<th>所在位置</th>
</tr>
</thead>
<tbody>
<tr>
<td>应用层</td>
<td>DNS，URI，HTML，HTTP，TSL/SSL，SMTP，RTP，FTP</td>
<td>应用层，表示层，会话层</td>
<td>应用程序</td>
</tr>
<tr>
<td>传输层</td>
<td>TCP，UDP，UDP-Lite，SCTP，DCCP</td>
<td>传输层</td>
<td>操作系统</td>
</tr>
<tr>
<td>网络层</td>
<td>ARP，IP,ICMP</td>
<td>互联网层</td>
<td>操作系统</td>
</tr>
<tr>
<td>网卡层</td>
<td></td>
<td>数据链路层</td>
<td>设备驱动与网络接口</td>
</tr>
<tr>
<td>硬件</td>
<td></td>
<td>物理层</td>
<td>设备驱动与网络接口</td>
</tr>
</tbody>
</table>
</div>
<h3 id="TCP-IP通信示例"><a href="#TCP-IP通信示例" class="headerlink" title="TCP/IP通信示例"></a>TCP/IP通信示例</h3><p>假设甲给乙发送邮件：</p>
<ol>
<li>应用程序处理：<ol>
<li>点击发送以后在表示层将编写好的邮件进行编码，然后等待会话层发送邮件</li>
</ol>
</li>
<li>TCP处理：<ol>
<li>TCP建立连接，发送数据，与断开连接，TCP提供可靠传输。</li>
<li>为实现可靠传输，在应用层的数据包上再次进行封装一个TCP首部(包含：源端口号，目的端口号，序号(本次发送的是发送端的低级和字节的序列号)，以及校验和) 接着发给IP网络层</li>
</ol>
</li>
<li>IP模块处理<ol>
<li>IP将TCP传来的数据包当作自己的数据并在TCP首部继续加上IP首部以生成IP数据包。IP首部包括：发送端IP，接收端IP，及判断信息。</li>
</ol>
</li>
<li>网络接口发送</li>
</ol>
<h3 id="IP地址"><a href="#IP地址" class="headerlink" title="IP地址"></a>IP地址</h3><h4 id="地址划分"><a href="#地址划分" class="headerlink" title="地址划分"></a>地址划分</h4><ol>
<li>A类以0开头的ip地址，前8位是网络标识，后面是主机标识</li>
<li>B类地址以10开头，前16位为网络标识，后面为主机标识</li>
<li>C类地址以110开头，前24位为网络标识，后面为主机标识</li>
<li>D类地址以1110开头，前32位为网络标识，常用于多播</li>
</ol>
<h4 id="子网掩码"><a href="#子网掩码" class="headerlink" title="子网掩码"></a>子网掩码</h4><p>如果只对地址进行划分的话，因为同一个网络标识的必须在同一个链路，所以为细化网络的大小，出现了子网掩码，以减少ip地址的浪费。</p>
<p>一个子网掩码，前面连续的1标识网络标识的长度，后面是连续的0，表示主机位</p>
<h4 id="IP数据报的分片与重组"><a href="#IP数据报的分片与重组" class="headerlink" title="IP数据报的分片与重组"></a>IP数据报的分片与重组</h4><p>因为不同类型的数据链路的使用目的不同，所以其MTU就不相同，IP不能被不同的数据链路所限制，所以其分片是寻找最小的MTU进行分片。</p>
<ol>
<li>首先将ip的分片标志位置1，如果数据包过大，则丢弃，根据icmp的不可达信息找到数据链路上的MTU。</li>
<li>下一次继续发送，直到没有ICMP后，将该值缓存10分钟左右，然后重新做一次路径MTU发现</li>
<li>TCP：根据路径MTU计算出最大段长度MSS，再根据这些进行数据报发送，因此，如果是TCP，再IP地址中不再会对其进行分片</li>
</ol>
<h4 id="报文格式"><a href="#报文格式" class="headerlink" title="报文格式"></a>报文格式</h4><p><img src="/2021/01/08/TCP-IP1/报文格式.jpg" alt="报文格式"></p>
<ol>
<li>总长度：表示首部与数据部分合起来的总字节数，一共16位，所以一个IP包理论上最长65535。</li>
<li>标识：16位，用于表示每一个IP数据包，同一个分片标识相同，如果标识相同，源地址目的地址不一样也不是同一个分片</li>
<li>标志：一共是3位，第一位必须是0；第二位表示是否可分片，0可以分配，1不可以；第三位表示分片时是否为最后一个包</li>
<li>片偏移：13位组成，表示每一个字节的位置，最大可表示65535个字节位置</li>
<li>TTL：8位组成，每经过一个路由器TTL减一，当其为0时丢弃该包。</li>
<li>协议：8位表示当前协议。</li>
<li>首部校验和：8位，用于校验ip数据报的首部是否出现差错</li>
<li>源地址：32位</li>
<li>目的地址：32位</li>
<li>可选项，只在进行实验与诊断时使用</li>
<li>填充，当出现可选字段时使用填充，让其保证是32位的整数倍</li>
</ol>
<p>首部校验和，将首部校验和默认为0，将首部所有数值相加后如果大于$2^16$则取低16位并将其+1，具体代码如下</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> org.junit.Test;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.util.ArrayList;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Ip</span> </span>&#123;</span><br><span class="line">    <span class="meta">@Test</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">CheckSum</span><span class="params">()</span></span>&#123;</span><br><span class="line">        ArrayList&lt;Long&gt; st = <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">        insert(st,<span class="number">0x45</span>,<span class="number">0x00</span>);<span class="comment">//版本，及TOS</span></span><br><span class="line">        insert(st,<span class="number">0x00</span>,<span class="number">0x2d</span>);<span class="comment">//总长度</span></span><br><span class="line">        insert(st,<span class="number">0x1e</span>,<span class="number">0xfa</span>);<span class="comment">//标识</span></span><br><span class="line">        insert(st,<span class="number">0x40</span>,<span class="number">0x00</span>);<span class="comment">//片偏移与分片标志</span></span><br><span class="line">        insert(st,<span class="number">0x71</span>,<span class="number">0x06</span>);<span class="comment">//TTL与协议</span></span><br><span class="line">        insert(st,<span class="number">0x00</span>,<span class="number">0x00</span>);<span class="comment">//校验和</span></span><br><span class="line">        insert(st,<span class="number">0x25</span>,<span class="number">0xfc</span>);</span><br><span class="line">        insert(st,<span class="number">0xe5</span>,<span class="number">0xa7</span>);<span class="comment">//源地址</span></span><br><span class="line">        insert(st,<span class="number">0xac</span>,<span class="number">0x1e</span>);</span><br><span class="line">        insert(st,<span class="number">0x28</span>,<span class="number">0xd8</span>);<span class="comment">//目的地址</span></span><br><span class="line">        System.out.printf(<span class="string">"%X\n"</span>,solve(st));</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">insert</span><span class="params">(ArrayList&lt;Long&gt; st,<span class="keyword">long</span> x,<span class="keyword">long</span> y)</span></span>&#123;</span><br><span class="line">        st.add(((x)&lt;&lt;<span class="number">8</span>)+y);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">long</span> <span class="title">solve</span><span class="params">(ArrayList&lt;Long&gt; arr)</span></span>&#123;</span><br><span class="line">        <span class="keyword">long</span> cksum = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">for</span>(Long it:arr)&#123;</span><br><span class="line">            cksum = cksum + it;</span><br><span class="line">            cksum = (cksum&amp;<span class="number">0xFFFF</span>) + (cksum&gt;&gt;<span class="number">16</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> ((~cksum)&amp;<span class="number">0xFFFF</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//0x0a37</span></span><br></pre></td></tr></table></figure>
<blockquote>
<p>发送前我们算出校验和后将其放到首部，在接收的时候将所有首部加起来算得的数据校验和是0则首部没有问题，否则首部出现差错，丢弃。</p>
</blockquote>

    </div>

    
    
    
      
  <div class="popular-posts-header">相关文章</div>
  <ul class="popular-posts">
    <li class="popular-posts-item">
      <div class="popular-posts-title"><a href="\2020\09\03\Http简述\" rel="bookmark">Http简述</a></div>
    </li>
    <li class="popular-posts-item">
      <div class="popular-posts-title"><a href="\2021\05\20\NAT与ARP及DNS\" rel="bookmark">NAT与ARP及DNS</a></div>
    </li>
    <li class="popular-posts-item">
      <div class="popular-posts-title"><a href="\2021\01\23\数据链路层\" rel="bookmark">数据链路层</a></div>
    </li>
  </ul>


      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C/" rel="tag"><i class="fa fa-tag"></i> 计算机网络</a>
          </div>

        
  <div class="post-widgets">
    <div class="wp_rating">
      <div id="wpac-rating"></div>
    </div>
  </div>


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2020/12/15/git%E5%88%9D%E5%AD%A6/" rel="prev" title="git初学">
      <i class="fa fa-chevron-left"></i> git初学
    </a></div>
      <div class="post-nav-item">
    <a href="/2021/01/11/mybatis%E5%AD%A6%E4%B9%A0/" rel="next" title="mybatis学习">
      mybatis学习 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  

  </div>


          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let activeClass = CONFIG.comments.activeClass;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#TCP-IP学习"><span class="nav-number">1.</span> <span class="nav-text">TCP/IP学习</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#OSi参考模型各个分层的作用"><span class="nav-number">1.1.</span> <span class="nav-text">OSi参考模型各个分层的作用</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#TCP-IP分层模型"><span class="nav-number">1.2.</span> <span class="nav-text">TCP/IP分层模型</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#TCP-IP通信示例"><span class="nav-number">1.3.</span> <span class="nav-text">TCP/IP通信示例</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#IP地址"><span class="nav-number">1.4.</span> <span class="nav-text">IP地址</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#地址划分"><span class="nav-number">1.4.1.</span> <span class="nav-text">地址划分</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#子网掩码"><span class="nav-number">1.4.2.</span> <span class="nav-text">子网掩码</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#IP数据报的分片与重组"><span class="nav-number">1.4.3.</span> <span class="nav-text">IP数据报的分片与重组</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#报文格式"><span class="nav-number">1.4.4.</span> <span class="nav-text">报文格式</span></a></li></ol></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="林木森"
      src="/images/vscode.jpg">
  <p class="site-author-name" itemprop="name">林木森</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">78</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">25</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">9</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
      <a href="https://github.com/Glad-hack/Glad-hack.github.io" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;Glad-hack&#x2F;Glad-hack.github.io" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
      <a href="mailto:treesirpeng@qq.com" rel="alternate" title="E-Mail" rel="noopener" target="_blank"> <i class="fa fa-fw fa-envelope"></i> E-Mail</a>
      </span>
      <span class="links-of-author-item">
      <a href="https://blog.csdn.net/qq_42937891" title="CSDN → https:&#x2F;&#x2F;blog.csdn.net&#x2F;qq_42937891" rel="noopener" target="_blank"><i class="fa fa-fw fa-copyright"></i>CSDN</a>
      </span>
      <span class="links-of-author-item">
      <a href="tencent://message/?uin=2972300671&Site=2972300671&Menu=yes" rel="alternate" title="QQ" rel="noopener" target="_blank"> <i class="fa fa-fw fa-qq"></i>QQ</a>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">林木森</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    <span title="站点总字数">149k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">2:16</span>
</div>

<!--
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> 强力驱动 v4.0.0
  </div> -->

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  
  <script color='0,0,255' opacity='0.5' zIndex='-1' count='99' src="/lib/canvas-nest/canvas-nest.min.js"></script>
  <script src="/lib/anime.min.js"></script>
  <script src="cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
  <script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script>
<script src="/js/utils.js"></script>
<script src="/js/schemes/pisces.js"></script>
<script src="/js/next-boot.js"></script>



  
  <script>
    (function(){
      var bp = document.createElement('script');
      var curProtocol = window.location.protocol.split(':')[0];
      bp.src = (curProtocol === 'https') ? 'https://zz.bdstatic.com/linksubmit/push.js' : 'http://push.zhanzhang.baidu.com/push.js';
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(bp, s);
    })();
  </script>



  <script>
  if (CONFIG.page.isPost) {
    wpac_init = window.wpac_init || [];
    wpac_init.push({
      widget: 'Rating',
      id: ,
      el: 'wpac-rating',
      color: 'fc6423'
    });
    (function() {
      if ('WIDGETPACK_LOADED' in window) return;
      WIDGETPACK_LOADED = true;
      var mc = document.createElement('script');
      mc.type = 'text/javascript';
      mc.async = true;
      mc.src = '//embed.widgetpack.com/widget.js';
      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(mc, s.nextSibling);
    })();
  }
  </script>

  <script src="/js/local-search.js"></script>












  

  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el: '#valine-comments',
      verify: true,
      notify: true,
      appId: 'BipSoA2zCEQAYpWMykiSStVv-gzGzoHsz',
      appKey: '5hT2yJIWHqMQf0KtlvPktoMw',
      placeholder: "快来留下你的足迹吧",
      avatar: 'mm',
      meta: guest,
      pageSize: '10' || 10,
      visitor: false,
      lang: '' || 'zh-cn',
      path: location.pathname,
      recordIP: false,
      serverURLs: ''
    });
  }, window.Valine);
});
</script>

  
  <script type="text/javascript"
  color="0,0,255" opacity='0.7' zIndex="-2" count="99" src="//cdn.bootcss.com/canvas-nest.js/1.0.0/canvas-nest.min.js"></script>
  
</body>
</html>
